# Run all test files
# Output files will be saved to examples/output/ directory

# Get the script directory
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$ProjectRoot = Split-Path -Parent $ScriptDir
$OutputDir = Join-Path $ScriptDir "output"

# Create output directory if it doesn't exist
if (-not (Test-Path $OutputDir)) {
    New-Item -ItemType Directory -Path $OutputDir | Out-Null
}

Write-Host "Starting all tests..." -ForegroundColor Green

# Test arithmetic instructions
Write-Host "`nTesting arithmetic instructions..." -ForegroundColor Yellow
Set-Location $ProjectRoot
cargo run -- examples/tests/test_arithmetic.asm examples/output/test_arithmetic.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

# Test stack instructions
Write-Host "`nTesting stack instructions..." -ForegroundColor Yellow
cargo run -- examples/tests/test_stack.asm examples/output/test_stack.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

# Test jump instructions
Write-Host "`nTesting jump instructions..." -ForegroundColor Yellow
cargo run -- examples/tests/test_jump.asm examples/output/test_jump.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

# Test data transfer instructions
Write-Host "`nTesting data transfer instructions..." -ForegroundColor Yellow
cargo run -- examples/tests/test_mov.asm examples/output/test_mov.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

# Test segment register instructions
Write-Host "`nTesting segment register instructions..." -ForegroundColor Yellow
cargo run -- examples/tests/test_segment.asm examples/output/test_segment.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

# Test interrupt instructions
Write-Host "`nTesting interrupt instructions..." -ForegroundColor Yellow
cargo run -- examples/tests/test_int.asm examples/output/test_int.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

# Test compare instructions
Write-Host "`nTesting compare instructions..." -ForegroundColor Yellow
cargo run -- examples/tests/test_cmp.asm examples/output/test_cmp.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

# Test conditional jump instructions
Write-Host "`nTesting conditional jump instructions..." -ForegroundColor Yellow
cargo run -- examples/tests/test_conditional_jump.asm examples/output/test_conditional_jump.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

# Test logical instructions
Write-Host "`nTesting logical instructions..." -ForegroundColor Yellow
cargo run -- examples/tests/test_logical.asm examples/output/test_logical.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

# Test shift instructions
Write-Host "`nTesting shift instructions..." -ForegroundColor Yellow
cargo run -- examples/tests/test_shift.asm examples/output/test_shift.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

# Test call instructions
Write-Host "`nTesting call instructions..." -ForegroundColor Yellow
cargo run -- examples/tests/test_call.asm examples/output/test_call.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

# Test mul/div instructions
Write-Host "`nTesting mul/div instructions..." -ForegroundColor Yellow
cargo run -- examples/tests/test_mul_div.asm examples/output/test_mul_div.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

# Test boundary conditions
Write-Host "`nTesting boundary conditions..." -ForegroundColor Yellow
cargo run -- examples/tests/test_boundary_immediate.asm examples/output/test_boundary_immediate.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

cargo run -- examples/tests/test_boundary_shift.asm examples/output/test_boundary_shift.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

cargo run -- examples/tests/test_boundary_jump.asm examples/output/test_boundary_jump.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

cargo run -- examples/tests/test_boundary_register.asm examples/output/test_boundary_register.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

cargo run -- examples/tests/test_boundary_operands.asm examples/output/test_boundary_operands.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

cargo run -- examples/tests/test_boundary_memory.asm examples/output/test_boundary_memory.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

cargo run -- examples/tests/test_boundary_mul_div.asm examples/output/test_boundary_mul_div.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

# Comprehensive test
Write-Host "`nRunning comprehensive test..." -ForegroundColor Yellow
cargo run -- examples/tests/test_all.asm examples/output/test_all.bin
if ($LASTEXITCODE -ne 0) { exit 1 }

Write-Host "`nAll tests completed! Output files saved to examples/output/ directory" -ForegroundColor Green

# Display output file list
Write-Host "`nGenerated binary files:" -ForegroundColor Cyan
Get-ChildItem (Join-Path $ScriptDir "output\*.bin") | Select-Object Name, @{Name="Size(bytes)";Expression={$_.Length}} | Format-Table -AutoSize

